import React, { useState } from 'react';

const SendOrder = () => {
    const [orderNum, setOrderNum] = useState<string>("123123");

    const handleSendOrder = async () => {
        const requestBody = { order_num: orderNum };
        const url = 'http://192.188.123.4:8080/webapi/getorder';
        // const url = 'http://192.188.123.2:4399/order/test';
        console.log('Sending request to:', url); // 确认 URL
        try {
            const response = await fetch(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(requestBody),
            });
            if (response.ok) {
                console.log("发送成功");
                const data = await response.json();
                console.log('Response data:', data);
            } else {
                console.error('Error in response:', response.statusText);
            }
        } catch (error) {
            console.error('Error in request:', error);
        }
    };
    

    return (
        <div>
            <input
                type="text"
                value={orderNum}
                onChange={(e) => setOrderNum(e.target.value)}
                placeholder="Enter Order Number"
            />
            <button onClick={handleSendOrder}>Send Order</button>
        </div>
    );
};

export default SendOrder;
